/*
 * @Author: 0x9DEFA478
 * @Date: 2021-06-01 20:51:38
 * @LastEditTime: 2021-09-29 15:34:39
 * @LastEditors: 0x9DEFA478
 * @Description: 底层定义头文件
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#ifndef __H_ThreadScheduler_LL_H_
#define __H_ThreadScheduler_LL_H_
#include "H_ThreadScheduler.h"

//用户包含 H_ThreadScheduler_LL.c H_ThreadScheduler.c会包含H_ThreadScheduler_LL.h
#include "Peripheral.h"



//栈标记值
#define vH_TS_StackMarkValue        0x55AA55AAU

//指针最大值 (不能为0)
#define vH_TS_VoidPtrMaxValue       ((void*)0xFFFFFFFFU)

//如果使能了CPU占用率统计(通过vH_TS_isEnableCPULoadCalculate来设置) 该段表示每运行多少时间后更新CPU占用值(时间由H_TS_GetDT来提供)
#define vH_TS_CPULoad_T             4000







//触发PendSV
#define oH_TS_CallPendSV()          do{\
                                      __schedule_barrier();\
                                      SCB->ICSR|=SCB_ICSR_PENDSVSET_Msk;\
                                      __schedule_barrier();\
                                      }while(0)

//挂起任务调度
#define oH_TS_SchedulerSuspend()    do{\
                                      __schedule_barrier();\
                                      H_TS_Core->SchedulerSuspend=-1;\
                                      __schedule_barrier();\
                                    }while(0)

//释放任务调度
#define oH_TS_ResumeScheduler_0()   do{\
                                      __schedule_barrier();\
                                      H_TS_Core->SchedulerSuspend=0;\
                                      if(H_TS_Core->SchedulerForIrq){\
                                        H_TS_Core->SchedulerForIrq=0;\
                                        oH_TS_CallPendSV();\
                                      }\
                                       __schedule_barrier();\
                                    }while(0)

//释放任务调度 并且固定触发一次PendSV
#define oH_TS_ResumeScheduler_1()   do{\
                                      __schedule_barrier();\
                                      H_TS_Core->SchedulerSuspend=0;\
                                      if(H_TS_Core->SchedulerForIrq){\
                                        H_TS_Core->SchedulerForIrq=0;\
                                      }\
                                      oH_TS_CallPendSV();\
                                      __schedule_barrier();\
                                    }while(0)


//挂起SysTick
#define oH_TS_SysTickSuspend()      do{\
                                      __schedule_barrier();\
                                      H_TS_Core->SysTickSuspend=-1;\
                                      __schedule_barrier();\
                                    }while(0)

//恢复SysTick
#define oH_TS_ReusmeSysTick()       do{\
                                      __schedule_barrier();\
                                      H_TS_Core->SysTickSuspend=0;\
                                      __schedule_barrier();\
                                    }while(0)

//中断中触发PendSV
#define oH_TS_ISR_CallPendSV()      do{\
                                      __schedule_barrier();\
                                      if(H_TS_Core->SchedulerSuspend!=0){\
                                        H_TS_Core->SchedulerForIrq=-1;\
                                      }else{\
                                        oH_TS_CallPendSV();\
                                      }\
                                      __schedule_barrier();\
                                    }while(0)



#endif //__H_ThreadScheduler_LL_H_
